package com.ruomeng.robot.util;

import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.text.NumberFormat;

import org.apache.commons.lang.StringUtils;




public class MoneyUtil {
	
	
	public static Long toLong(Double money) {
		
		NumberFormat nf = new DecimalFormat("#.##");
		Double d = Double.valueOf(nf.format(money))*100;
		long moneyInt = d.intValue();
		return moneyInt;
		
	}
	
	public static double toDoulbe(Long money) {
		if(money == null)  return 0;
		double temp  = money/100.0;
		NumberFormat nf = new DecimalFormat("############0.00");
		return Double.valueOf(nf.format(temp));
		
	}
    public static double toDoulbe(Double money) {
    	if(money == null)  return 0;
		double temp  = money/100.0;
		NumberFormat nf = new DecimalFormat("############0.00");
		return Double.valueOf(nf.format(temp));
		
	}
	
     public static String toDoulbeString(Long money) {
		if(money == null)  return "0.00";
		double temp  = money/100.0;
		NumberFormat nf = new DecimalFormat("############0.00");
		return nf.format(temp);
		
	}
     public static Double toDoulbe2(Double money) {
    	 if(money == null)  return 0d;
    	 NumberFormat nf = new DecimalFormat("############0.00");
    	 return Double.valueOf(nf.format(money));
    	 
     }
     
    
     /**
      * 元转化为分
      * @param @return
      * @author guohao
      * @date 2016年4月7日 下午1:39:11
      * @since $
      */
     public static long toPenny(Double money) {
    	 if(money == null) return 0;
    	 BigDecimal bigDecimal = BigDecimal.valueOf(money);
 		 bigDecimal = bigDecimal.multiply(BigDecimal.valueOf(100));
    	 return bigDecimal.longValue();
     }
	

	public static String toString(Long money) {
		if(money == null) return "";
		double temp  = money/100.0;
		NumberFormat nf = new DecimalFormat("############0.00");
		return nf.format(temp);
		
	}
	
	public static Integer toInteger(String price) {
		if(StringUtils.isEmpty(price)) return null;
		Integer temp  = (int)(Double.valueOf(price)*100);
		return temp;
		
	}
	
	public static String toStringInt(Integer money) {
		if(money == null) return "";
		double temp  = money/100.0;
		NumberFormat nf = new DecimalFormat("############0.00");
		return nf.format(temp).replaceAll("((?:\\.00)|(?:\\.0)|(?:0))$", "");
		
	}
	
	/**
	 *去掉小数点后面的0
	 */
	public static String toStringInt(String money) {
		if(StringUtils.isEmpty(money)) return "";
		return money.replaceAll("((?:\\.00)|(?:\\.0)|(?:0))$", "");
		
	}
	
	public static String toStringMoney(Long money) {
		if(money == null) return "";
		long temp  = money/100;
		return temp+"";
		
	}
	public static String toStringMoney(Integer money) {
		if(money == null) return "";
		long temp  = money/100;
		return temp+"";
		
	}
	
	public static void main(String[] args) {
		//System.out.println(toLong(2.333333));
		System.out.println(toDoulbe(5000l));
	}

}
